package Test;

import java.util.ArrayList;
import java.util.List;

public class dome7 {
    public static void main(String[] args) {
        //创建集合对象
        List list=new ArrayList();

        //创建元素对象
        Student student1=new Student("张三",12);
        Student student2=new Student("王五",13);
        Student student3=new Student("李四",14);
        Student student4=new Student("牛五",15);

        //将元素添加到集合中
        list.add(student1);
        list.add(student2);
        list.add(student3);
        list.add(student4);

        //直接打印集合
        System.out.println(list);

        //遍历集合
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }
}
